package net.wanho.controller;

import net.wanho.entity.User;
import net.wanho.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * Author：汤小洋
 * Date：2025-08-05 10:57
 * Description：<描述>
 */
@RestController
@RequestMapping("/users")
@RefreshScope // nacos配置自动刷新
public class UserController {

    @Value("${server.port}")
    private int port;

    @Value("${spring.datasource.url}")
    private String url;

    @Value("${shop.share.name}")
    private String name;

    @GetMapping("/test")
    public String test(){
        return "provider--->" + port + "---------->" + url + "----------->" + name;
    }

    @GetMapping
    public AjaxResult list(String username){
        User user = new User(1001, username, "123");
        return AjaxResult.success(user);
    }

    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Integer id){
        User user = new User(id, "admin", "123");
        return AjaxResult.success(user);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody User user){
        return AjaxResult.success("添加成功:" + user);
    }

}
